var AU = require("AudioUtils").inst;
let self;
cc.Class({
	extends: cc.Component,

	properties: {
		loadbar: {//加载进度
			default: null,
			type: cc.ProgressBar
		},
		/*loadtext: {//进度显示
		    default: null,
		    type: cc.Label
		},*/
	},
	
	init: function(){
		self.loadbar.progress=0;
		var jiduNode=cc.find("Canvas/Main Camera/uiMain/Loading/Progress_Lab");
		self.jn = jiduNode.getComponent(cc.Label);
	},
	
	onLoad: function(){
		self = this;
		self.init();
		
		self._loadRes();
	},

	/**
	 * 初始音频资源加载
	 */
	_loadRes: function() {
		var loadbar =  self.loadbar;
		var jindu = 0;
		self.is_loading = true;
		cc.loader.loadResDir("audio", self._progressCallback.bind(self), self._completeCallback.bind(self));
	},
	
	_progressCallback: function(completedCount, totalCount, res) {
			var loadbar =  self.loadbar;
			var jindu = 0;
			if(totalCount !== 0 && self.is_loading === true) {
				jindu = completedCount / totalCount;
			}
			loadbar.progress = jindu;
			var number_jindu = parseInt(jindu * 100);
			
			self.jn.string = number_jindu+"%";
	},
	
	_completeCallback: function(error, res) {
		var blockInputs = cc.find('Canvas/Main Camera/uiMain/Loading');
		blockInputs.active = false;
		
		AU.init();//音效组件初始化
		AU.playMusic(MUSIC_SPACE_TRIP,true);
	},

});